package com.rgp.servicepay.config;

import com.alipay.api.AlipayApiException;
import com.alipay.api.DefaultAlipayClient;
import com.rgp.servicepay.constant.AlipayProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author nhp
 * @version 1.0
 * @description TODO
 * @date 2024-04-26 22:41
 */
@Configuration
public class AlipayConfigUtils {

    @Autowired
    private AlipayProperties alipayProperties;

    @Bean
    public DefaultAlipayClient defaultAlipayClient() throws AlipayApiException {
        com.alipay.api.AlipayConfig config = new com.alipay.api.AlipayConfig();
        config.setServerUrl(alipayProperties.getServerUrl());
        config.setAppId(alipayProperties.getAppId());
        config.setPrivateKey(alipayProperties.getPrivateKey());
        config.setFormat(alipayProperties.getFormat());
        config.setAlipayPublicKey(alipayProperties.getAlipayPublicKey());
        config.setCharset(alipayProperties.getCharset());
        config.setSignType(alipayProperties.getSignType());
        DefaultAlipayClient defaultAlipayClient = new DefaultAlipayClient(config);
        return defaultAlipayClient;
    }
}
